cmake_minimum_required(VERSION 3.0.0)
project(cm21060201 VERSION 0.1.0)

cmake_policy(SET CMP0074 NEW)

message("\n\n")
message("=====> CMakeTest 2021.6.2.1")

set(MY_PATH_INCLUDE)
message("MY_PATH_INCLUDE: ${MY_PATH_INCLUDE}")

find_path(MY_INCULDE_DIR boost/align.hpp
    PATHS D:/dev/v142-x64/boost_1_76_0
)
message("MY_INCULDE_DIR: ${MY_INCULDE_DIR}")

set(LIB_NAMES"")
foreach(LIBNAME aa aaa c e)
    LIST(APPEND LIB_NAMES "${MY_INCULDE_DIR}/${LIBNAME}")
endforeach(LIBNAME)

message("LIB_NAMES := ${LIB_NAMES}")


MACRO(FIND_DEPENDENCY DEPNAME INCLUDEFILE LIBRARY_NAMES_BASE SEARCHPATHLIST DEBUGSUFFIX EXSUFFIX)

    MESSAGE(STATUS "searching ${DEPNAME} -->${INCLUDEFILE}<-->${LIBRARY_NAMES_BASE}<-->${SEARCHPATHLIST}<--")

    SET(MY_PATH_INCLUDE )
    SET(MY_PATH_LIB )

    FOREACH( MYPATH ${SEARCHPATHLIST} )
        SET(MY_PATH_INCLUDE ${MY_PATH_INCLUDE} ${MYPATH}/include)
        SET(MY_PATH_LIB ${MY_PATH_LIB} ${MYPATH}/lib)
        FOREACH(LIBNAME ${LIBRARY_NAMES_BASE})
            SET(MY_PATH_INCLUDE ${MY_PATH_INCLUDE} ${MYPATH}/${LIBNAME}/include)
            SET(MY_PATH_LIB ${MY_PATH_LIB} ${MYPATH}/${LIBNAME}/lib)
        ENDFOREACH(LIBNAME)
    ENDFOREACH( MYPATH ${SEARCHPATHLIST} )

    message("====> ${MY_PATH_INCLUDE}")
    message("----> ${CMAKE_SYSTEM_INCLUDE_PATH}")

    FIND_PATH("${DEPNAME}_INCLUDE_DIR" ${INCLUDEFILE}
      ${MY_PATH_INCLUDE}
      NO_DEFAULT_PATH
    )
    MARK_AS_ADVANCED("${DEPNAME}_INCLUDE_DIR")
    MESSAGE( " ${DEPNAME}_INCLUDE_DIR --> ${${DEPNAME}_INCLUDE_DIR}<--")

    SET(LIBRARY_NAMES "")
    FOREACH(LIBNAME ${LIBRARY_NAMES_BASE})
        LIST(APPEND LIBRARY_NAMES "${LIBNAME}${EXSUFFIX}")
    ENDFOREACH(LIBNAME)
    FIND_LIBRARY("${DEPNAME}_LIBRARY"
        NAMES ${LIBRARY_NAMES}
      PATHS ${MY_PATH_LIB}
      NO_DEFAULT_PATH
    )
    SET(LIBRARY_NAMES_DEBUG "")
    FOREACH(LIBNAME ${LIBRARY_NAMES_BASE})
        LIST(APPEND LIBRARY_NAMES_DEBUG "${LIBNAME}${DEBUGSUFFIX}${EXSUFFIX}")
    ENDFOREACH(LIBNAME)
    FIND_LIBRARY("${DEPNAME}_LIBRARY_DEBUG"
        NAMES ${LIBRARY_NAMES_DEBUG}
      PATHS ${MY_PATH_LIB}
      NO_DEFAULT_PATH
    )
    MARK_AS_ADVANCED("${DEPNAME}_LIBRARY")
    #MESSAGE( " ${DEPNAME}_LIBRARY --> ${${DEPNAME}_LIBRARY}<--")
    SET( ${DEPNAME}_FOUND "NO" )
    IF(${DEPNAME}_INCLUDE_DIR AND ${DEPNAME}_LIBRARY)
      SET( ${DEPNAME}_FOUND "YES" )
      IF(NOT ${DEPNAME}_LIBRARY_DEBUG)
          MESSAGE("-- Warning Debug ${DEPNAME} not found, using: ${${DEPNAME}_LIBRARY}")
          SET(${DEPNAME}_LIBRARY_DEBUG "${${DEPNAME}_LIBRARY}")
      ENDIF(NOT ${DEPNAME}_LIBRARY_DEBUG)

      SET(${DEPNAME}_LIBRARIES debug ${${DEPNAME}_LIBRARY_DEBUG} optimized ${${DEPNAME}_LIBRARY} )

    ENDIF(${DEPNAME}_INCLUDE_DIR AND ${DEPNAME}_LIBRARY)



ENDMACRO(FIND_DEPENDENCY DEPNAME INCLUDEFILE LIBRARY_NAMES_BASE SEARCHPATHLIST DEBUGSUFFIX)

set(OSG_3RDPARTY_BIN D:/dev/v142-x64/osg_3rdparty_bin)


set(ZLIB_ROOT D:/dev/v142-x64/osg_3rdparty_bin)
set(COMPONENT_NAME zlib)
string(TOUPPER ${COMPONENT_NAME} COMPONENT_NAME)
find_package(${COMPONENT_NAME})
message("${COMPONENT_NAME}_FOUND := " ${${COMPONENT_NAME}_FOUND})
message("ZLIB_INCLUDE_DIRS := " ${ZLIB_INCLUDE_DIRS})
message("ZLIB_LIBRARY := " ${ZLIB_LIBRARY})
message("ZLIB_VERSION_STRING := " ${ZLIB_VERSION_STRING})


# FIND_DEPENDENCY(ZLIB zlib.h "z;zlib;zlib1" ${OSG_3RDPARTY_BIN} "D" "")

FIND_DEPENDENCY(PNG png.h "libpng;libpng13;libpng15;libpng16" ${OSG_3RDPARTY_BIN} "D" "")

set(COMPONENT_NAME PNG)
message("${COMPONENT_NAME}_FOUND := " ${${COMPONENT_NAME}_FOUND})
message("${COMPONENT_NAME}_INCLUDE_DIR := " ${${COMPONENT_NAME}_INCLUDE_DIR})
message("${COMPONENT_NAME}_LIBRARY := " ${${COMPONENT_NAME}_LIBRARY})
message("${COMPONENT_NAME}_VERSION_STRING := " ${${COMPONENT_NAME}_VERSION_STRING})